import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
	state: {
		shareTime: 0, // 点击分享的时间
		fromPage: '', // 跳转前的页面
		rwPage: '', // 跳转前的页面
		tidus: '', // 由链接获取，代表当前店铺的idus
		storeName: '', // 店铺名字
		hasLogin: false,
		userInfo: { // 用户信息
			'昵称': '未登录',
			'头像': '/static/missing-face.png',
			_id: '',
			vip: 0,
			RMB: 0,
			SIM: 0,
			storeName: '某某店'
		}
	},
	mutations: {
		setStoreName(state, storeName) {
			state.storeName = storeName
		},
		setShareTime(state, time) {
			state.shareTime = time
		},
		setFromPage(state, fromPage) {
			state.fromPage = fromPage
		},
		phonePage(state, rwPage) {
			state.rwPage = rwPage
		},
		setTidus(state, tidus) {
			state.tidus = tidus
		},
		login(state, provider) {

			state.hasLogin = true;
			state.userInfo = provider;
			uni.setStorage({//缓存用户登陆状态
			    key: 'userInfo',  
			    data: provider  
			}) 
			console.log(state.userInfo);
		},
		updateUserInfo(state, newUserInfo) {
			state.userInfo = {
				...state.userInfo,
				...newUserInfo
			}
			uni.setStorage({//缓存用户登陆状态
			    key: 'userInfo',  
			    data: state.userInfo  
			})
		},
		logout(state) {
			state.hasLogin = false;
			state.userInfo = {};
			uni.removeStorage({  
                key: 'userInfo'  
            })
		}
	},
	actions: {
	
	}
})

export default store
